package com.itheima.pojo;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 通用返回结果，服务端响应的数据最终都会封装成此对象
 *
 * @param <T>
 */
public class JsonResult<T> implements Serializable {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String msg; //错误信息

    private T data; //数据

    public static <T> JsonResult<T> success(T object) {
        JsonResult<T> jsonResult = new JsonResult<T>();
        jsonResult.data = object;
        jsonResult.code = 1;
        return jsonResult;
    }

    public static <T> JsonResult<T> error(String msg) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.msg = msg;
        jsonResult.code = 0;
        return jsonResult;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


}
